import {
    post,
    get,
    put,
    Delete,
    form
} from "@/axios/http.js";
import {
    basicApi
} from "@/api/index.js"
import { setCookie,removeCookie,getCookie } from "@/utils/auth";
//模块数据
export default {
    namespaced: true,
    state: {
        leftMenu: [],
        userRecommend:[],
        leftMenuCache: {},
    },
    actions: {
        // 关注-左侧关注列表-(关注(全部关注、已分组、未分组)、好友(全部、未分组、已分组)、粉丝(全部、已分组、未分组))
        concernedAllList({}, params){
            return post(basicApi.studentAnswering.concernedAllList, params).then(res => {
                return res
            });
        },
        // 删除好友
        friendDel({}, params){
            return get(basicApi.studentAnswering.friendDel, params).then(res => {
                return res
            });
        },
        // 修改分组信息
        groupUpdate({}, params){
            return get(basicApi.studentAnswering.groupUpdate, params).then(res => {
                return res
            });
        },
        // 移除分组，分组下有好友，禁止删除
        groupDel({}, params){
            return get(basicApi.studentAnswering.groupDel, params).then(res => {
                return res
            });
        },
        // 移动用户到分组-批量
        groupMove({}, params){
            return put(basicApi.studentAnswering.groupMove, params).then(res => {
                return res
            });
        },
        // 关注-粉丝-已关注(添加关注)
        addFollow({}, params){
            return get(basicApi.studentAnswering.addFollow, params).then(res => {
                return res
            });
        },
        // 关注-黑名单-列表展示
        backlist({}, params){
            return get(basicApi.studentAnswering.backlist, params).then(res => {
                return res
            });
        },
        // 关注-粉丝-加入黑名单
        backlistjoin({}, params){
            return get(basicApi.studentAnswering.backlistjoin, params).then(res => {
                return res
            });
        },
        // 关注-粉丝-右侧列表
        beanlist({}, params){
            return get(basicApi.studentAnswering.beanlist, params).then(res => {
                return res
            });
        },
        // 关注-粉丝-移除粉丝
        beanremove({}, params){
            return get(basicApi.studentAnswering.beanremove, params).then(res => {
                return res
            });
        },
        // 关注-粉丝-移除黑名单
        blackremove({}, params){
            return get(basicApi.studentAnswering.blackremove, params).then(res => {
                return res
            });
        },
        // 关注-右侧列表-创建分组
        concernSave({}, params){
            return get(basicApi.studentAnswering.concernSave, params).then(res => {
                return res
            });
        },
        // 关注-右侧列表
        concerndList({}, params){
            return get(basicApi.studentAnswering.concerndList, params).then(res => {
                return res
            });
        },
        // 关注-左侧关注列表
        concernedTreeList({state}, params){
            return get(basicApi.studentAnswering.concernedTreeList, params).then(res => {
                if(res.data.code==200){
                    state.leftMenuCache = res.data.result
                    state.leftMenu = res.data.result
                    return res
                }else{
                    return res
                }
            });
        },
        // 关注-已关注好友
        recommendList({commit}, params){
            var timeOut = 0
            var tokenId = setInterval(getToken, 200);
            function getToken() {
                if (getCookie("ACCESS_TOKEN") || timeOut>3000) {
                clearInterval(tokenId);
                return get(basicApi.studentAnswering.recommend, params).then(res => {
                    if(res&&res.data.code==200){
                        commit('INIT_USERRECOMMEND',res.data.result.list)
                        return res
                    }
                });
                } else {
                    timeOut +=200
                }
            }
        },
        // 关注-好友列表
        recommend({commit}, params){
            return post(basicApi.studentAnswering.recommend, params).then(res => {
                return res
            });
        },
        // 关注-粉丝、关注-备注名
        remark({}, params){
            return get(basicApi.studentAnswering.remark, params).then(res => {
                return res
            });
        },
        // 关注-粉丝-当前用户下的分组
        selectGroup({}, params){
            return post(basicApi.studentAnswering.selectGroup, params).then(res => {
                return res
            });
        },
        // 关注-粉丝-添加为当前用户下的分组内
        updateGroup({}, params){
            return post(basicApi.studentAnswering.updateGroup, params).then(res => {
                return res
            });
        },
    },
    mutations: {
        INIT_USERRECOMMEND(state,params){
            state.userRecommend = params
        },
        INIT_LEFTMENU(state,params){
            state.leftMenu = params
        }
    },
}